package cn.stylefeng.guns.modular.xlb.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.xlb.entity.XlbApiDeliToStore;
import cn.stylefeng.guns.modular.xlb.mapper.XlbApiDeliToStoreMapper;
import cn.stylefeng.guns.modular.xlb.model.params.XlbApiDeliToStoreParam;
import cn.stylefeng.guns.modular.xlb.model.result.XlbApiDeliToStoreResult;
import  cn.stylefeng.guns.modular.xlb.service.XlbApiDeliToStoreService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 同步门店送达信息 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2025-06-16
 */
@Service
public class XlbApiDeliToStoreServiceImpl extends ServiceImpl<XlbApiDeliToStoreMapper, XlbApiDeliToStore> implements XlbApiDeliToStoreService {

    @Override
    public void add(XlbApiDeliToStoreParam param){
        XlbApiDeliToStore entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(XlbApiDeliToStoreParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(XlbApiDeliToStoreParam param){
        XlbApiDeliToStore oldEntity = getOldEntity(param);
        XlbApiDeliToStore newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public XlbApiDeliToStoreResult findBySpec(XlbApiDeliToStoreParam param){
        return null;
    }

    @Override
    public List<XlbApiDeliToStoreResult> findListBySpec(XlbApiDeliToStoreParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(XlbApiDeliToStoreParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(XlbApiDeliToStoreParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private XlbApiDeliToStore getOldEntity(XlbApiDeliToStoreParam param) {
        return this.getById(getKey(param));
    }

    private XlbApiDeliToStore getEntity(XlbApiDeliToStoreParam param) {
        XlbApiDeliToStore entity = new XlbApiDeliToStore();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
